package com.tensquare.qa.controller;

import com.tensquare.qa.service.ProblemService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * & ProjectName：  tensquare-parent
 * & PackageName:   com.tensquare.qa.controller
 * & Creation_Date： 2020/3/31 00:48
 * & Author：しの
 * ----------------------------------
 * & Description:
 */
@RestController
@RequestMapping("/problem")
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    //1 最新回答列表
    @GetMapping("/newlist/{labelid}/{page}/{size}")
    public Result newlist(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        PageResult pageResult= null;
        try {
            pageResult = problemService.newlist(labelid,page,size);
        return new Result(true,StatusCode.OK,"查询最新回答成功",pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,StatusCode.ERROR,"查询最新回答失败");
    }

    //2 热门问题列表
    @GetMapping("/hotlist/{labelid}/{page}/{size}")
    public Result hotlist(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        PageResult pageResult=problemService.hotlist(labelid,page,size);
        return new Result(true,StatusCode.OK,"热门问题列表成功",pageResult);
    }
}
